﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace NuMetaheuristics
{
    /// <summary>
    /// Contains all of the functionality necessary for an algorithm to work 
    /// in the desired problem space. This includes: production, initialization,
    /// and evaluation of candidate solutions.
    /// </summary>
    public interface IContext<G>
        where G : IGenotype
    {
        /// <summary>
        /// Produce a new candidate solution, with the option to initialize, 
        /// make valid, and evaluate the candidate as well.
        /// </summary>
        /// <returns>A new genome object of the given genotype.</returns>
        G Produce(bool initialize, bool makeValid, bool evaluate);

        /// <summary>
        /// Initialize the given candidate solution.
        /// </summary>
        /// <param name="candidate"></param>
        void Initialize(ref G candidate);

        /// <summary>
        /// Evaluate the quality of a candidate and update the fitness 
        /// accordingly.
        /// </summary>
        /// <param name="operand">The candidate solution to be evaluated.</param>
        void Evaluate(ref G candidate);

        /// <summary>
        /// Check the validity of a candidate.
        /// </summary>
        /// <param name="operand">The candidate solution to be evaluated.</param>
        /// <returns>True if the given candidate represents a valid solution. False 
        /// otherwise.</returns>
        bool IsValid(G candidate);

        /// <summary>
        /// If necessary, modify the given candidate to make it a valid solution.
        /// </summary>
        /// <param name="candidate">The candidate solution to validated and possibly 
        /// modified.</param>
        void MakeValid(ref G candidate);
    }
}
